﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using AutoWelding.BLL;
using AutoWelding.Models;

namespace AutoWelding.Views.Users
{
    public partial class UpdatePwdForm : Form
    {
        public UpdatePwdForm()
        {
            InitializeComponent();
        }

        UserBLL userBLL = new UserBLL();
        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void UpdatePwdForm_Load(object sender, EventArgs e)
        {
            
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            string oldpwd = txt_oldpwd.Text;
            string newpwd = txt_newpwd.Text;
            string newpwd1 = txt_newpwd1.Text;

            UserModel user = userBLL.GetUserById(Convert.ToInt32(this.Tag));
            if (user != null)
            {
                if (user.UserPassword == oldpwd)
                {
                    if (newpwd == newpwd1)
                    {
                        user.UserPassword = newpwd;
                        if (userBLL.UpdateUser(user))
                        {
                            MessageBox.Show("修改密码成功！");
                            this.Close();
                            //后续可以加  关闭程序  或者  退出登录程序  先不加
                        }
                        else
                        {
                            MessageBox.Show("修改密码失败！");
                        }
                    }
                    else
                    {
                        MessageBox.Show("两次输入的密码不一致！");
                    }
                }
                else
                {
                    MessageBox.Show("原密码输入错误！");
                }
            }
        }

    }
}
